//
//  ping_observer_impl.h
//  mac_ping_network
//
//  Created by Constantine Mars on 5/15/13.
//  Copyright (c) 2013 Constantine Mars. All rights reserved.
//

#ifndef __mac_ping_network__ping_observer_impl__
#define __mac_ping_network__ping_observer_impl__

#include <iostream>
#include "icmp/icmp.h"

class PingObserverImpl : public IPingObserver
{
public:
    PingObserverImpl(unsigned int attempts, long long* ping_timeout)
    : attempts_(attempts), ping_timeout_(ping_timeout)
    {
        *ping_timeout_ = 0;
    }
    
    void OnReply(unsigned short, unsigned int ttl, long long time)
    {
        *ping_timeout_ += time;
        std::clog << "OnReply: ttl=" << ttl << ", time=" << time << std::endl;
    }
    
    void OnRequestTimeout(long long time)
    {
        *ping_timeout_ += time;
        std::clog << "OnRequestTimeout: time=" << time << std::endl;
    }
    
    void OnComplete()
    {
        *ping_timeout_ /= attempts_;
    }
private:
    unsigned int attempts_;
    long long* ping_timeout_;
};

#endif /* defined(__mac_ping_network__ping_observer_impl__) */
